<?php


namespace FoxLib\Services;


use FoxLib\Exceptions\InvalidNonceException;
use GuzzleHttp\Client;

class NonceService
{
    /**
     * @param $userId
     * @param $code
     * @throws InvalidNonceException
     */
    public static function check($userId, $code)
    {
        $httpClient = new Client();
        $rpcUrl = config('app.internal_services_host.admin') . '/internal/nonce/check';
        $response = $httpClient->request('POST', $rpcUrl, [
            'json' => [
                'userId' => $userId,
                'code' => $code
            ]
        ]);
        if ($response->getStatusCode() != 200) {
            throw new InvalidNonceException();
        }
    }
}